package cn.always.xiajia.admin.oauth2.entity;

import java.time.LocalDateTime;
import java.util.List;

import com.baomidou.mybatisplus.annotation.KeySequence;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;

import cn.always.xiajia.framework.common.enums.UserTypeEnum;
import cn.always.xiajia.framework.mybatis.core.entity.BaseEntity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

/**
 * OAuth2 刷新令牌
 * 
 * @author xgj
 *
 */
@TableName(value = "sys_oauth2_refresh_token", autoResultMap = true)
@KeySequence("sys_oauth2_refresh_token_seq")
@Data
@EqualsAndHashCode(callSuper = true) // 比较对象
@Accessors(chain = true) // set返回对象
@NoArgsConstructor
@AllArgsConstructor
public class OAuth2RefreshToken extends BaseEntity {

	private static final long serialVersionUID = 620448905952152675L;

	/**
	 * OAuth2 刷新令牌 ID
	 */
	@TableId
	protected Long id;

	/**
	 * 刷新令牌
	 */
	protected String refreshToken;

	/**
	 * 用户Id
	 */
	private Long userId;

	/**
	 * 用户账号
	 */
	protected String userCode;

	/**
	 * 用户名称
	 */
	protected String userName;

	/**
	 * 用户类型(UserTypeEnum)
	 *
	 * 关联 {@link UserTypeEnum}
	 */
	protected String userType;

	/**
	 * 客户端编号
	 *
	 * 关联 {@link OAuth2Client#getId()}
	 */
	protected String clientId;

	/**
	 * 授权范围
	 */
	@TableField(typeHandler = JacksonTypeHandler.class)
	protected List<String> scopes;

	/**
	 * 过期时间
	 */
	protected LocalDateTime expiresTime;

}
